<%@ Control Language="c#" Inherits="LocalBoard.Web.MessageView" CodeFile="MessageView.ascx.cs" %>
<%@ Register TagPrefix="uc1" TagName="RateArticle" Src="RateArticle.ascx" %>
<asp:Panel ID="msgHeadDisplay" Runat="server">
<table class="messageHd" cellSpacing="0" cellPadding="0" width="100%" border="0">
  <tr bgColor="#f5f5f5">
    <td colSpan="2">
<asp:Label id="messageId" Runat="server" Visible="False"></asp:Label><b>No.</b> 
<asp:Label id="messageNo" Runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B> 
      <asp:Literal id="subjectDisplay" Runat="server" EnableViewState="False"></asp:Literal></b></td>
  </tr>
  <tr bgColor="#f5f5f5">
    <td align=left><b>Name(id):</b> 
<asp:Label id="postedByName" Runat="server"></asp:Label>(<asp:HyperLink id="postedByUserId" NavigateUrl="~/UserInfo.aspx?userId={0}" Target="blank" Runat="server" />)</td>
    <td align=right><b>Date:</b> 
<asp:Label id="date" Runat="server"></asp:Label><b>Hits:</b> 
<asp:Label id="numberOfView" Runat="server"></asp:Label></td>
	</tr>
</table>
<asp:Repeater id="attachments" runat="server">
		<HeaderTemplate>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td>Attachments:</td>
				</tr>
		</HeaderTemplate>
		<ItemTemplate>
			<tr>
				<td>
					<asp:HyperLink ID="attachLink" Runat="server" /></td>
			</tr>
		</ItemTemplate>
		<FooterTemplate>
			</table>
		</FooterTemplate>
	</asp:Repeater>
</asp:Panel>
<asp:Panel ID="msgHeadEdit" Visible="False" Runat="server"><B>Subject:</B> 
<asp:TextBox id="subject" Runat="server" Visible="False" EnableViewState="True" MaxLength="60" Width="500"></asp:TextBox>
<asp:RequiredFieldValidator id="subjectValidator" runat="server" ErrorMessage="'Subject' must not be left blank." Display="Dynamic" ControlToValidate="subject"></asp:RequiredFieldValidator><BR>
<asp:Panel id="buttons" Runat="server"><A onmouseover="this.style.cursor='hand'" 
onclick="popImage()" onmouseout="this.style.cursor='default'">Upload 
Photo</A>&nbsp;&nbsp; <A onmouseover="this.style.cursor='hand'" 
onclick="popFile('clubstation')" onmouseout="this.style.cursor='default'">Upload 
File</A>&nbsp;&nbsp; <A onmouseover="this.style.cursor='hand'" onclick="popLink()" 
onmouseout="this.style.cursor='default'">Upload Multimedia</A>&nbsp;&nbsp; <A 
onmouseover="this.style.cursor='hand'" onclick="popPoll()" 
onmouseout="this.style.cursor='default'">Make Poll</A><BR>
<TABLE cellSpacing="0" cellPadding="0" width="570" border="0">
  <TR>
    <TD width="440"><SELECT size="3" name="attachfilelist"> <OPTION 
        value="">----------------------------- Attached files 
        ----------------------------</OPTION></SELECT> </TD>
    <TD 
    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px" 
    width="130"><A onmouseover="this.style.cursor='hand'" onclick="removeAttach()" 
      onmouseout="this.style.cursor='default'">Delete</A><BR><IMG height="4" 
      width="0"><BR><INPUT style="WIDTH: 40px" readOnly type="text" 
      value="0" name="attachsizesum">KB / 2048KB <INPUT type="hidden" 
      name="attachfileyn"> <INPUT type="hidden" name="attachimageyn"> <INPUT 
      type="hidden" name="attachpollyn"> <INPUT type="hidden" name="attachfiles"> <INPUT 
      type="hidden" name="attachsizes"> <INPUT type="hidden" value="0" 
      name="attachsizerealsum"> <INPUT type="hidden" name="attachpolls"> 
</TD></TR></TABLE>
<SCRIPT language=javascript>
function open_window(url, name, width, height, feature)
{
	var oWnd;

	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) { // browser version >= ie 4
		if(width < window.screen.width && height < window.screen.height) {
			var windowX = Math.ceil( (window.screen.width  - width) / 2 );
			var windowY = Math.ceil( (window.screen.height - height) / 2 );

			oWnd = window.open(url, name, feature+",width=" + width +",height=" + height+",left="+windowX+",top="+windowY);
		}
		else {
			oWnd = window.open(url, name, feature+",width=" + width +",height=" + height);
		}
	}
	else {
		oWnd = window.open(url, name, feature+",width=" + width +",height=" + height);
	}
	return oWnd;
}

function open_wnd(url, name, width, height)
{
	var oWnd = '';
	if (!oWnd.closed && oWnd.location)
	{
		oWnd.location.href = url;
	}
	else
	{
		oWnd = open_window(url, name, width, height, "toolbar=0,menubar=0,resizable=no,scrollbars=no");
		if (!oWnd.opener) oWnd.opener = self;
	}
	if (window.focus) {oWnd.focus()}
	return oWnd;
}

function popImage()
{
    open_wnd("AttachFile.aspx", "addimage", 330, 280);
}

function popFile(cluburl)
{
    open_wnd("AttachFile.aspx", "addfile", 330, 200);
}

function popPoll()
{
    open_wnd("AddPoll.aspx", "addpoll", 330, 260);
}

function addList(dirname, filename, filesize)
{
    if (filename == 'poll@nhn')
    {
        document.all.attachfilelist.add(new Option('Poll item added' , filename));
        //document.all.attachfilelist.options[document.all.attachfilelist.length-1].selected = true;        
    }
    else
    {
        if (filesize)
        {    
            calcFileSize(filesize, 1);
            document.all.attachfilelist.add(new Option(filename + "   " + parseInt(parseInt(filesize)/1024) + "KB", dirname + filename));
            //document.all.attachfilelist.options[document.all.attachfilelist.length-1].selected = true;
        }
        else
            document.all.attachfilelist.add(new Option(filename, dirname + filename));
            //document.all.attachfilelist.options[document.all.attachfilelist.length-1].selected = true;            
    }
}

function calcFileSize(filesize, oper)
{
    if (oper == 1)
    {
        document.all.attachsizerealsum.value = parseInt(document.all.attachsizerealsum.value) + parseInt(filesize);
    }
    else
    {
        document.all.attachsizerealsum.value = parseInt(document.all.attachsizerealsum.value) - parseInt(filesize);
    }
    
    document.all.attachsizesum.value = parseInt(document.all.attachsizerealsum.value/1024);    
}

function addPoll(attachpolls)
{
    document.all.attachpollyn.value = "Y";
    document.all.attachpolls.value = attachpolls;
    //document.all.imgPoll.src = "http://cafeimgs.naver.com/img/colorset/white/btn_poll_edit.gif";
}

function removePoll()
{
    document.all.attachpollyn.value = "";
    document.all.attachpolls.value = "";
    //document.all.imgPoll.src = "http://cafeimgs.naver.com/img/btn_poll.gif";
}

function addFile(dirname, filename, filesize, filetype)
{
    if (filetype == "F") document.all.attachfileyn.value = "Y";
    if (filetype == "I") document.all.attachimageyn.value = "Y";
    document.all.attachfiles.value = document.all.attachfiles.value + dirname + filename + ";" + filetype + "|";
    document.all.attachsizes.value = document.all.attachsizes.value + filesize + "|";
}

function removeFile(index)
{
    arrAttachfile = document.all.attachfiles.value.split("|");
    arrAttachsize = document.all.attachsizes.value.split("|");

    calcFileSize(arrAttachsize[index], -1);    
    
    arrAttachfile.remove(index);
    arrAttachsize.remove(index);
    document.all.attachfiles.value = arrAttachfile.join("|");
    document.all.attachsizes.value = arrAttachsize.join("|");
    
    
    document.all.attachfileyn.value = "";
    document.all.attachimageyn.value = "";
    for (var i = 0; i<arrAttachfile.length; i++)
    {
        if (arrAttachfile[i].match(/F$/))
        {
            document.all.attachfileyn.value = "Y";
        }
        if (arrAttachfile[i].match(/I$/))
        {
            document.all.attachimageyn.value = "Y";
        }
    }
}

function addAttach(filepath, filename, filesize, filetype)
{
	addList(filepath, filename, filesize);
	addFile(filepath, filename, filesize, filetype);
}

function removeAttach()
{
    var attachlist = document.all.attachfilelist;
    
    if (attachlist.selectedIndex <= 0)
        return;

    if (attachlist.options[attachlist.selectedIndex].value == "poll@nhn")
        removePoll();
    else
        removeFile(attachlist.selectedIndex-1);
    
    attachlist.remove(attachlist.selectedIndex);    
}

function IsPollAttached()
{
	return (document.all.attachpollyn.value == 'Y');
}

function GetPoll()
{
	return document.all.attachpolls.value;
}
		</SCRIPT>
</asp:Panel>
</asp:Panel>
<p>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td class="messageBody">
				<asp:TextBox ID="body" Width="100%" Height="300" Visible="False" Runat="server" TextMode="MultiLine"
					EnableViewState="True" />
<script language="JavaScript" type="text/javascript" src="Editor/wysiwyg.js">
</script>
<script language="javascript1.2">
  generate_wysiwyg('messageView_body');
</script>
				<asp:Repeater ID="pollResult" Runat="server" Visible="False">
					<ItemTemplate>
						<asp:Label ID="pollItemName" Runat="server" />
						<asp:Label ID="votedPercentage" Runat="server" /><br>
					</ItemTemplate>
				</asp:Repeater>
				<asp:RadioButtonList ID="pollItemList" Runat="server" Visible="False" />
				<asp:Button ID="votePollBtn" Runat="server" Text="Vote" Visible="False" onclick="votePollBtn_Click" />
				<asp:Literal ID="bodyDisplay" EnableViewState="False" Runat="server" />
			</td>
		</tr>
	</table>
</p>
<asp:Repeater ID="shortMemoList" Runat="server">
	<HeaderTemplate>
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
	</HeaderTemplate>
	<ItemTemplate>
		<tr class="comment">
			<td>
				<asp:ImageButton ID="shortMemoDelete" ImageUrl="~/images/delete.gif" BorderWidth="0" OnClick="shortMemoDelete_Click" 
 Runat="server" />&nbsp;
				<asp:Label ID="shortMemoPostedByName" Runat="server" />(
				<asp:Label ID="shortMemoPostedById" Runat="server" />)&nbsp;
				<asp:Label ID="shortMemoDate" Runat="server" />&nbsp;
				<asp:Literal ID="shortMemoBody" Runat="server" />
			</td>
		</tr>
	</ItemTemplate>
	<FooterTemplate>
		</table>
	</FooterTemplate>
</asp:Repeater>
<br>
<asp:Panel ID="displayMode" EnableViewState="True" Runat="server">
<asp:Label id="commentLabel" CssClass="postComment" Runat="server">Comment: </asp:Label>
<asp:TextBox id="shortMemo" Runat="server" MaxLength="300" Width="300"></asp:TextBox>
<asp:Button id="postShortMemo" Runat="server" Text="Post" onclick="postShortMemo_Click"></asp:Button><br>
<br>
<asp:Button id="edit" Runat="server" Text="Edit" onclick="Edit_Click"></asp:Button> | 
<asp:Button id="reply" Runat="server" Text="Reply" onclick="Reply_Click"></asp:Button> | 
<asp:Button id="delete" Runat="server" Text="Delete" onclick="delete_Click"></asp:Button>
</asp:Panel>
<asp:Panel ID="editMode" Visible="False" EnableViewState="True" Runat="server">
<CENTER>
<asp:Button id="postMessage" Runat="server" Text="Post" onclick="PostMessage_Click"></asp:Button></CENTER>
</asp:Panel>
<br>
<uc1:RateArticle id="rateArticle" runat="server"></uc1:RateArticle>
